package com.XZDP.config;

import com.XZDP.Interceptor.FlushedInterceptor;
import com.XZDP.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//注册拦截器
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate redisTemplate;

    //重写添加拦截器方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(redisTemplate)).excludePathPatterns(
                "/user/code",
                "/user/login",
                "/shop/**",
                "/list/**",
                "/voucher/**",
                "/blog/hot",
                "/shop-type/**"
        ).order(1);
        //拦截所有路径
        registry.addInterceptor(new FlushedInterceptor(redisTemplate)).addPathPatterns("/**").order(0);
    }
}
